﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">


                <div class="layui-form-item">
                    <label class="layui-form-label">羊场全称</label>
                    <div class="layui-input-block">
                        <input type="text" name="farmFullName" id="farmFullName" placeholder="请输入" class="layui-input">
                    </div>
                </div>



                <div class="layui-form-item">
                    <label class="layui-form-label">羊场简称</label>
                    <div class="layui-input-block">
                        <input type="text" id="farmShortName" placeholder="请输入" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">羊场规模</label>
                    <div class="layui-input-block">
                        <select name="city" id="farmSize" lay-filter="aihao">
                            <option value="">请选择羊场规模</option>
                            <option value="500只以下">500只以下</option>
                            <option value="500-1000只">500-1000只</option>
                            <option value="1000-3000只">1000-3000只</option>
                            <option value="3000-5000只">3000-5000只</option>
                            <option value="5000只以上">5000只以上</option>
                        </select>
                    </div>
                </div>

                <div>
                    <label class="layui-form-label">所在区域</label>
                    <div class="layui-input-inline">
                        <select id="provinceId" lay-filter="provincet">
                            <option value="">请选择</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select id="directlyId" lay-filter="city">
                            <option value="">请选择</option>
                        </select>
                    </div>

                    <div class="layui-input-inline">
                        <select id="countyId" lay-filter="directly">
                            <option value="">请选择</option>
                        </select>
                    </div>

                </div>






                <div class="layui-form-item">
                    <label class="layui-form-label">详细地址</label>
                    <div class="layui-input-block">
                        <input type="text" id="farmDetailedAddress" placeholder="请输入" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">建账日期</label>
                    <div class="layui-input-block">
                        <input type="date" id="farmCreateTime" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">负责人</label>
                    <div class="layui-input-block">
                        <select name="city" id="persId" lay-filter="testSelect">
                            <option value="">请选择负责人</option>
                            <option value="张三">张三</option>
                            <option value="李四">李四</option>
                            <option value="王五">王五</option>
                            <option value="赵六">赵六</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">管理部门</label>
                    <div class="layui-input-block">
                        <select name="city" id="departmentId" lay-filter="testSelect">
                            <option value="">请选择部门类型</option>
                            <option value="行政管理">行政管理</option>
                            <option value="生产加工">生产加工</option>
                            <option value="业务销售">业务销售</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">是否启用</label>
                    <div class="layui-input-block">
                        <input type="radio" name="formState" value="true" title="启用" checked>
                        <input type="radio" name="formState" value="false" title="禁用">
                    </div>
                </div>


                <div class="layui-form-item" style="float:right">
                    <button type="button" class="layui-btn layui-bg" onclick="Add()">保存</button>
                </div>



            </div>


        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>

</body>

</html>

<script>

    var form = layui.form;
    var $ = layui.jquery;
    $(function () {
        bangsheng();

    })

    function bangsheng() {
        $.ajax({
            url: "http://localhost:5123/api/Regions/ProvinceQuerys",
            data: JSON.stringify({}),
            type: "post",
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                console.log(res)
                $.each(res.data, function () {
                    $("#provinceId").append(`<option value="${this.provinceId}">${this.provinceName}</option>`);
                })
                form.render('select'); // 重新渲染下拉框
            }
        })
    }
    var provincetId1 = 0;
    var cityid = 0;
    form.on('select(provincet)', function (data) {
        provincetId1 = data.value;
        console.log(provincetId1)
        $("#directlyId").empty();
        $("#directlyId").append('<option value="">请选择</option>');
        $("#countyId").empty();
        $("#countyId").append('<option value="">请选择</option>');
        bangshi()

    });
    form.on('select(city)', function (data) {
        cityid = data.value;
        console.log(provincetId1)
        $("#countyId").empty();
        $("#countyId").append('<option value="">请选择</option>');
        bangxian();

    });


    function fanT() {
        var farmId =
    }





    function bangshi() {
        var provinceId = $("#provinceId").val();
        $.ajax({
            url: "http://localhost:5123/api/Regions/CityQuerys",
            data: JSON.stringify({ provinceId: provincetId1 }),
            type: "post",
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                console.log(res.data)

                $.each(res.data, function () {
                    $("#directlyId").append(`<option value="${this.directlyId}">${this.directlyName}</option>`);
                })
                form.render('select'); // 重新渲染下拉框
            }

        })
    }

    function bangxian() {
        var directlyId = $("#directlyId").val();
        $.ajax({
            url: "http://localhost:5123/api/Regions/CountyQuerys",
            data: JSON.stringify({ directlyId: cityid }),
            type: "post",
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                $.each(res.data, function () {
                    $("#countyId").append(`<option value="${this.countyId}">${this.countyName}</option>`);
                })
                form.render('select'); // 重新渲染下拉框
            }

        })
    }








    function Add() {

        var data = {
            farmNumber: '',
            farmFullName: $("#farmFullName").val(),
            formState: $("[name=formState]:checked").val() == "true" ? true : false,
            farmShortName: $("#farmShortName").val(),
            farmSize: $("#farmSize").val(),
            provinceId: $("#countyId").val(),
            farmDetailedAddress: $("#farmDetailedAddress").val(),
            farmCreateTime: $("#farmCreateTime").val(),
            persId: $("#persId").val(),
            departmentId: $("#departmentId").val(),
            directlyId: $("#directlyId").val(),
            countyId: $("#countyId").val()
            // flatId: '',
        }
        console.log(data)
        $.ajax({
            url: "http://localhost:5123/api/SheepFarms/AddSheepFarms",
            type: 'post',
            data: JSON.stringify(data),
            dataType: "json",
            contentType: "application/json",
            success: res => {
                if (res.code == 0) {
                    layer.msg(res.msg);
                }
                else {
                    layer.msg(res.msg);
                }
            }
        })
    }


</script>